package com.qf.boot1.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author 刘欣
 * @createTime 2023/2/2 15:18
 * @description
 */
@Aspect
@Component
@Slf4j
public class NullAspect {

    @Pointcut("@annotation(com.qf.boot1.annotation.NullAnnotation)")
    public void nullPointCut() {

    }

    @Before("nullPointCut()")
    public void before(JoinPoint jp) throws Exception {
        Object[] args = jp.getArgs();
        for (Object arg : args) {
            if (arg == null) {
                log.debug("参数为空");
                throw new Exception("参数不能为空！");
            }
        }

    }
}
